<?php
header("content-type:text/html;charset=utf8");
$id=$_GET['id'];
$filename="$id.html";
//浏览次数
$dbh = new  PDO ( 'mysql:host=localhost;dbname=mhsw' , 'root' , 'root' );
$dbh->exec("update jj set a=a+1 where id='$id'");
$time=filectime($filename);
//echo date('Y-m-d H:i:s',$time);die;
//判断文件是否存在且没有过期
if(file_exists($filename)&&time()-$time<5)
{
    echo "现在是静态化";
    include $filename;
}
else
{
    if(file_exists($filename))
    {
        unlink($filename);
    }
    $dbh = new  PDO ( 'mysql:host=localhost;dbname=mhsw' , 'root' , 'root' );
//拼接字符串
    $sql='select * from jj where id='.$id;
    $arr=$dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
    //开启缓存
    ob_start();
    //把模板放到缓冲区
    include "moban.php";
    file_put_contents($filename,ob_get_clean());
    include $filename;
//print_r($arr);die;
    //第一次
//    $mo=file_get_contents('moban.php');
//    $mo=str_replace('{username}',$arr['username'],$mo);
//echo $mo;die;/////////
    //第二次
//    file_put_contents($filename,$mo);
//    include $filename;

}
